package com.example.smartcity.ui.more.Adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.smartcity.R
import com.example.smartcity.SmartCityApplication.Companion.context
import com.example.smartcity.logic.utils.Toast.Companion.showToast
import com.example.smartcity.ui.smartCity.activitytModule.SmViewPagerActivity
import com.example.smartcity.ui.more.model.MoreEntity

/**
 * 全部服务RecyclerView适配器
 */
class MoreRecyclerViewAdapter(val data: List<MoreEntity>) : RecyclerView.Adapter<MoreRecyclerViewAdapter.ViewHolder>() {
    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view){
        // 获取控件
        val moreImageView = view.findViewById<ImageView>(R.id.re_imgView)
        val moreTitle = view.findViewById<TextView>(R.id.re_tvTitle)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.recyclerview_item_more, parent, false)
        val view = ViewHolder(root)

        // 点击事件
        view.itemView.setOnClickListener {
            "发生了未知的错误！".showToast()
        }

        return view
    }

    override fun getItemCount() = data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val list = data[position]
        Glide.with(context)
            .load(list.imageView)
            .into(holder.moreImageView)
        holder.moreTitle.text = list.title
    }


}